package com.thd.springboottest.jpa.repository;

import com.thd.springboottest.jpa.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * com.thd.springboottest.jpa.repository.UserRespository
 *
 * @author: wanglei62
 * @DATE: 2022/7/5 16:39
 **/

@Repository
public interface UserRepository extends JpaRepository<User, String> {

    public List<User> findByNameAndAge(String name, Integer age);
    public List<User> findByName(String name);
    public List<User> findByNameOrAge(String name,Integer age);

    @Query(value="select user.id from jpa_test_user user where user.user_name like %?1% ", nativeQuery = true)
    public List<User> queryByNativeSQL(String name);

    @Query(value="select user.id from jpa_test_user user where user.user_name like %:uname% ", nativeQuery = true)
    public List<User> queryByNativeSQL2(@Param("uname") String name);
}
